function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
let l1 = {
    val: 1,
    next: {
        val: 2,
        next: {
            val: 2,
            next: {
                val: 3,
                next: {
                    val: 3,
                    next: {
                        val: 4,
                        next: null
                    }
                }
            }
        }
    }
}
var deleteDuplicates = function (head) {
    let list = new ListNode()
    let cur = list
    let arr = []
    while (head) {
        if (arr.findIndex((element) => element === head.val) === -1) {
            arr.push(head.val)
            cur.next = head
            cur = cur.next
        }
        head = head.next
    }
    cur.next = null
    return list.next
};
function printList(head) {
    let current = head;
    let result = [];
    while (current) {
        result.push(current.val);
        current = current.next;
    }
    console.log(result.join(' -> '));
}
let p = deleteDuplicates(l1)
printList(p)